package a3;

import java.awt.Point;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;

public class State {

	public Location locPrey;
	public TreeSet<Location> locOthers;
	public int ID;
	Environment env;

	public State(Environment env, int ID) {
		this.ID = ID;
		this.env = env;
		Location locPrey1 = env.getPrey().Location;
		if(ID == -1){
			this.locPrey = locPrey1;
		}
		else
		{
			this.locPrey = (Location)env.getPredators().get(ID).Location;
			
		}	
		TreeSet<Location> locOthers = new TreeSet<Location>();
		Vector<Predator> allPreds = Environment.getPredators();
		for(int i = 0; i<allPreds.size(); i++)
		{
			if(i != ID)
			{
				locOthers.add(Tools.mod(Tools.subLocs((Location)allPreds.get(i).Location, locPrey),env.BoardSize));
			}
			
		}
		if( ID == -1)
		{
			this.locPrey = new Location(0,0);
		}
		else
			this.locPrey = Tools.mod(Tools.subLocs(locPrey1,(Location)env.getPredators().get(ID).Location),env.BoardSize);
		
		
		this.locOthers = (TreeSet<Location>)locOthers;
	}
	
	public State( Location locPrey , TreeSet<Location> locOthers) {
		this.locPrey = locPrey;
		this.locOthers = locOthers;
	}
	
	
	public String toString()
	{
		String str = ID + " " + locPrey.toString() + " {";
		for(Location l : locOthers)
		{
			str += l.toString() + " ";
		}
		str += "} ";
		return str;
	}
	
	public State clone(){
		TreeSet<Location> treeSetClone = new TreeSet<Location>();
		for(Location l : locOthers)
		{
			treeSetClone.add((Location)l.clone());
		}
		State clone = new State((Location)this.locPrey.clone(), treeSetClone);
		return clone;
	}
	
	public int hashCode(){
		return this.toString().hashCode();
	}
}
